<?php $this->fetch('public/head') ?>
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this"><a href="<?php echo url('index') ?>">月供管理</a></li>
        </ul>
        <div class="layui-tab-content">
            <form class="layui-form layui-form-pane" action="<?php echo url('index') ?>" method="post">
                <div class="layui-inline">
                    <label class="layui-form-label">添加月供</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name"  placeholder="请输入新月供范围" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn">添加</button>
                </div>
            </form>
            <hr>


                <div class="layui-tab-item layui-show">
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th style="width: 30px;">ID</th>
                            <th>名称</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach($list as $v): ?>
                            <tr>
                                <td><?php echo $v['id'] ?></td>
                                <td>
                                    <input name="name" type="text" id="change_sort_<?php echo $v['id'] ?>" value="<?php echo $v['name'] ?>" data-url="<?php echo url('edit?id='.$v['id']) ?>" onchange="change_sort(<?php echo $v['id'] ?>)">
                                <td>
                                    <a href="<?php echo url('delete?id='.$v['id']) ?>" class="layui-btn layui-btn-danger layui-btn-xs ajax-delete">删除</a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        </tbody>
                    </table>
                    <!--分页-->
                </div>
        </div>
    </div>

<?php $this->fetch('public/script') ?>

<script>
    //修改排序值
    function change_sort(id){
        var name = $("#change_sort_"+id).val();
        var _url = $("#change_sort_"+id).attr("data-url");
        $.ajax({
            type:'POST',
            url:_url,
            dataType: "json",
            data:{"name":name},
            success:function(info){
                if (info.code === 1) {
                    setTimeout(function () {
                        location.href = info.url;
                    }, 1000);
                }
                layer.msg(info.msg);
            }
        })
    }
</script>